<?php
/**
 * Created by PhpStorm.
 * User: ZT
 * Date: 2017/12/12 0012
 * Time: 下午 4:17
 */
namespace frontend\controllers;
use backend\component\ResultFormat;
use frontend\component\FrontendBaseController;
use yii\web\Controller;
use common\models\info\Comment;
class CommentController extends FrontendBaseController
{
    public $layout = "/main";

    public function actionIndex()
    {
        return $this->render('index');
    }
    public function actionInsert(){
        $model = new Comment();
        $post = \Yii::$app->request->post();
        $model->setAttributes($post);
        if (!$model->save()) {
            return ResultFormat::error($model->getErrorsToString());
        }
        $data = $model->getNewData();
        return ResultFormat::success("操作成功",$data);
    }
    public function actionList(){
        $article_id = \Yii::$app->request->get("article_id",0);
        $page = \Yii::$app->request->get("page");
        $pageSize = \Yii::$app->request->get("pageSize",10);
        $model = new Comment();
        $data = $model->getDataByArtPage($article_id,$page,$pageSize);
        return ResultFormat::success('SUCCESS',$data);
    }
    public function actionSub(){
        $article_id = \Yii::$app->request->get("article_id",0);
         $target_id = \Yii::$app->request->get("target_id",0);
         $page = \Yii::$app->request->get("page");
        $pageSize = \Yii::$app->request->get("pageSize",10);
        $model = new Comment();
        $data = $model->getDialogList($target_id,$article_id,$page,$pageSize);
        return ResultFormat::success('SUCCESS',$data);
    }

    /*留言板*/
    public function actionMessage(){
        $page = \Yii::$app->request->get("page");
        $pageSize = \Yii::$app->request->get("pageSize",10);
        $model = new Comment();
        $data = $model->getDataByMessage($page,$pageSize);
        return ResultFormat::success('SUCCESS',$data);
    }
}